package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.OmFile;
import com.ruoyi.system.service.IOmFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 文件Controller
 *
 * @author ruoyi
 * @date 2023-11-26
 */
@RestController
@RequestMapping("/system/file")
public class OmFileController extends BaseController {
    @Autowired
    private IOmFileService omFileService;

    /**
     * 查询文件列表
     */
   //  @PreAuthorize("@ss.hasPermi('system:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(OmFile omFile) {
        startPage();
        List<OmFile> list = omFileService.selectOmFileList(omFile);
        return getDataTable(list);
    }

    /**
     * 查询文件列表
     */
   //  @PreAuthorize("@ss.hasPermi('system:file:list')")
    @GetMapping("/listByDuty")
    public List<OmFile> listByDuty(OmFile omFile) {
        List<OmFile> list = omFileService.selectOmFileList(omFile);
        return list;
    }

    /**
     * 导出文件列表
     */
   //  @PreAuthorize("@ss.hasPermi('system:file:export')")
    @Log(title = "文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OmFile omFile) {
        List<OmFile> list = omFileService.selectOmFileList(omFile);
        ExcelUtil<OmFile> util = new ExcelUtil<OmFile>(OmFile.class);
        util.exportExcel(response, list, "文件数据");
    }

    /**
     * 获取文件详细信息
     */
   //  @PreAuthorize("@ss.hasPermi('system:file:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(omFileService.selectOmFileById(id));
    }

    /**
     * 新增文件
     */
   //  @PreAuthorize("@ss.hasPermi('system:file:add')")
    @Log(title = "文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OmFile omFile) {
        return toAjax(omFileService.insertOmFile(omFile));
    }

    /**
     * 修改文件
     */
   //  @PreAuthorize("@ss.hasPermi('system:file:edit')")
    @Log(title = "文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OmFile omFile) {
        return toAjax(omFileService.updateOmFile(omFile));
    }

    /**
     * 删除文件
     */
   //  @PreAuthorize("@ss.hasPermi('system:file:remove')")
    @Log(title = "文件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(omFileService.deleteOmFileByIds(ids));
    }
}
